//
//  Mail_GetDetail_Task.m
//  iphone.mobileoa
//
//  Created by 李亚春 on 13-6-3.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "Mail_GetDetail_Task.h"
#import "WebServiceHelper.h"
#import "StringUtil.h"
#import "ATTACHList.h"
#import "GDataXMLNode.h"

@implementation Mail_GetDetail_Task

-(void)execute
{
    NSString *ValidateData = [self.params objectForKey:@"ValidateData"];
    NSString *url = [self.params objectForKey:@"url"];
    NSString *wsNamespace = [self.params objectForKey:@"namespace"];
    NSString *userguid = [self.params objectForKey:@"userguid"];
    NSString *MailGuid = [self.params objectForKey:@"MailGuid"];
    WebServiceHelper *webserviceHelper = [[WebServiceHelper alloc]initWebServiceWithUrl:url wsNamespace:wsNamespace method:@"Mail_GetDetail"];
    NSString *ParasXml = @"<?xml version=\"1.0\" encoding=\"gb2312\"?><paras><UserGuid>%@</UserGuid><MailGuid>%@</MailGuid></paras>";
    ParasXml = [NSString stringWithFormat:ParasXml,userguid,MailGuid];
    ParasXml = [StringUtil filterXmlString:ParasXml];
    [webserviceHelper addParameterForString:@"ValidateData" value:ValidateData];
    [webserviceHelper addParameterForString:@"ParasXml" value:ParasXml];
    NSString *bs = webserviceHelper.start;
    [self sendDataRefreshUI:bs];
}

+(NSMutableArray *)getAttackList:(NSString *)_xml
{
    _xml = [StringUtil getXMLFormatedAttributeIncludeTag:_xml :@"ATTACHList"];
    
    GDataXMLDocument *doc = [[[GDataXMLDocument alloc] initWithXMLString:_xml  options:0 error:nil]autorelease];
    GDataXMLElement *rootElement = [doc rootElement];
    NSArray *arrays = [rootElement elementsForName:@"SingleFile"];
    NSMutableArray *listmp = [[NSMutableArray alloc]init];
    
    for (GDataXMLElement *arr in arrays)
    {
        ATTACHList *m = [[ATTACHList alloc]init];
        GDataXMLElement *AttachGuid = [[arr elementsForName:@"AttachGuid"] objectAtIndex:0];
        m.AttachGuid = [AttachGuid stringValue];
        
        GDataXMLElement *ATTACHFILENAME = [[arr elementsForName:@"ATTACHFILENAME"] objectAtIndex:0];
        m.ATTACHFILENAME = [ATTACHFILENAME stringValue];
        
        GDataXMLElement *isBigFile = [[arr elementsForName:@"isBigFile"] objectAtIndex:0];
        m.isBigFile = [isBigFile stringValue];
        
        GDataXMLElement *DownLoadUrl = [[arr elementsForName:@"DownLoadUrl"] objectAtIndex:0];
        m.DownLoadUrl = [DownLoadUrl stringValue];
        
        [listmp addObject:m];
        [m release];
    }
    
    return [listmp autorelease];
}

@end
